package com.tony.business.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tony.domain.bo.JsonResult;
import com.tony.domain.dto.SelectAdminMenuPageDTO;
import com.tony.domain.enumerate.DeleteEnum;
import com.tony.domain.vo.AdminMenuPageVO;
import com.tony.mapper.domain.po.AdminMenu;
import com.tony.mapper.mapper.AdminMenuMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @author tony
 * @date 2020/2/27 7:18 下午
 */
@Service
public class AdminMenuService extends ServiceImpl<AdminMenuMapper, AdminMenu> {

    public JsonResult<Page<AdminMenuPageVO>> selectAdminMenuPage(SelectAdminMenuPageDTO pageDTO) {
        QueryWrapper<AdminMenuPageVO> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isNotEmpty(pageDTO.getName()), "am.name", pageDTO.getName());
        wrapper.eq(pageDTO.getParentId() != null, "am.parent_id", pageDTO.getParentId());
        wrapper.eq("am.is_enable", pageDTO.getIsEnable().getValue());
        wrapper.eq("am.is_del", DeleteEnum.UNDELETED.getValue());
        wrapper.orderByAsc("am.code");
        Page<AdminMenuPageVO> page = super.baseMapper.selectPageVO(new Page<>(pageDTO.getCurrent(), pageDTO.getSize()), wrapper);
        return new JsonResult<>(page);
    }
}

